package com.wmuj.controller;

import com.wmuj.annotation.LogOperation;
import com.wmuj.pojo.Clazz;
import com.wmuj.pojo.ClazzsQueryParam;
import com.wmuj.pojo.PageResult;
import com.wmuj.pojo.Result;
import com.wmuj.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/** 员工管理 */
@RequestMapping("/clazzs")
@Slf4j
@RestController
public class ClazzController {

  @Autowired private ClazzService clazzService;

  /** 班级列表查询 分页查询 */
  @GetMapping
  public Result queryClazzsList(ClazzsQueryParam clazzsQueryParam) {
    log.info("分页查询，参数：{}", clazzsQueryParam);
    PageResult<Clazz> pageResult = clazzService.queryClazzsList(clazzsQueryParam);
    return Result.success(pageResult);
  }

  /** 根据id删除班级路径参数 */
  @LogOperation

  @DeleteMapping("{id}")
  public Result delete(@PathVariable Integer id) {
    log.info("根据id删除班级，id为：{}", id);
    clazzService.delete(id);
    return Result.success();
  }

  /** 添加班级信息 */
  @LogOperation
  @PostMapping
  public Result addInfo(@RequestBody Clazz clazz) {
    log.info("添加班级信息，参数为：{}", clazz);
    clazzService.addInfo(clazz);
    return Result.success();
  }

  /** 根据id查询班级信息 */
  @GetMapping("/{id}")
  public Result findById(@PathVariable Integer id) {
    log.info("根据id查询班级信息，id为：{}", id);
    Clazz clazz = clazzService.findById(id);
    return Result.success(clazz);
  }

  /** 更新班级信息 */
  @LogOperation

  @PutMapping
  public Result update(@RequestBody Clazz clazz) {
    log.info("更新班级信息，参数为：{}", clazz);
    clazzService.update(clazz);
    return Result.success();
  }
  /**
   * 查询所有班级
   * /clazzs/list
   */
  @GetMapping("/list")
  public Result list(){
    log.info("查询所有班级");
    return Result.success(clazzService.findAllList());
  }
}
